<?php
require_once 'BaseController.php';

/**
 * 賃料×間取り検索クラス<br />
 *
 * @package    apamanshop
 * @author     SS笹川
 * @copyright  コピーライト(要確認)
 */
class Search_ChinryomadorisearchController extends Search_BaseController
{
	public function indexAction()
	{
		$this->setMainTemplate('cms_search.tpl');
		/*
		 * 基本情報設定
		 */
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_CHINRYOMADORI, "chinryomadorisearch");

		//CSSの定義（デザイン）
		$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));

    	/*
    	 * モデルオブジェクト生成
    	 */
		$this->_model_research = new Search_Model_ResearchPanel();
		$this->_model_campain    = new Search_Model_Campaignsearch();

		// 検索タイプ生成
		$this->_data['srhtype_jyusyo']   = Apm_Config_Search::SRHTYPE_JYUSYO;
		$this->_data['srhtype_enseneki'] = Apm_Config_Search::SRHTYPE_ENSENEKI;
		// 単一選択用フラグ
		$this->_data['SelFlag'] = 1;
		// 市区町村選択なし
    	$this->_data['SelCyoNull'] = "1";
		// 駅名選択なし
    	//$this->_data['SelEkiNull'] = "1";
		// 物件検索なし
		$this->_data['RstNull'] = "1";

        // 以下、検索画面によって条件分けする。
        // 都道府県検索画面の出力(初期呼び出し時)
		if (! $this->_model_common->checkvalue($this->_params, "PrefCd"))
    	{
			// メインテンプレート
			$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/chinryo.tpl';
			$this->addMetaCss('/search_share/chinryo/css/add.css',array('type' => 'text/css','media' => 'all'));
			$this->addMetaJs('/app/js/search/Seltodohuken.js');
			// 検索ボタン
			$this->_data['search_button_tpl'] = APPLICATION_PATH . '/modules/search/views/helpers/btn_chinryo_pref.tpl';
			// メインブロック
			$this->_main_helper = $this->getApmHelper('seltodohuken_radio_renew.tpl');
			// リード文
			$this->_data['read_text'] = 'それぞれの地域の1ルーム、1K/1DK、1LDK、2D/2DK、2LDK、3K/3DK、3LDK、4Kなど、間取り毎に公開物件数と物件一覧をご覧いただけます。これからのお部屋探しにご活用ください。';
			
			return;
			
			// H1のタイトル
			//$this->_data['h1_title'] = 'ご希望の都道府県を選択してください。';
			// JavaScript
			//$this->addMetaJs($this->_aplbaseurl . 'js/search/Seltodohuken.js');

			//$this->_main_helper = $this->_todohuken_radio_selsrh_helper;
    	}
		// 政令指定都市・市区検索画面の出力（市区町村選択画面で検索時）
		else if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_JYUSYO
		         && ! $this->_model_common->checkvalue($this->_params, "CityCd") && $this->_model_common->checkvalue($this->_params, "SiteitosiCd") )
		{

            // 市区町村モデル
		    $this->_model_sikucyoson = new Search_Model_Selsikucyoson();

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の政令指定都市を選択してください。';
			// JavaScript
			$this->addMetaJs($this->_aplbaseurl . 'js/search/Selsikucyoson.js');

			$this->_data['selcity'] = array();
			$this->_data['selcity'] = $this->_model_sikucyoson->getSiteiShikuData($this->_params, "1");

			// 表示用データに変換
			$this->_model_sikucyoson->convertShikucyosonData($this->_data);
			$this->_data['selSiteitosiKbn'] = "1";

			$this->_main_helper = $this->_shikucyoson_helper;
		}
		// 市区町村検索画面の出力（都道府県検索画面で検索時）
		else if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_JYUSYO
		         && ! $this->_model_common->checkvalue($this->_params, "CityCd") )
		{
			$params = array(
					  'SrhKbn'  => $this->_params['SrhKbn']
					, 'SrhType' => $this->_params['SrhType']
					, 'PrefCd'  => $this->_params['PrefCd']
				);
			Apm_Util::redirect($this->_baseurl."search/chinryomadorisearch/city/", $params);
			exit();

            // 市区町村モデル
		    $this->_model_sikucyoson = new Search_Model_Selsikucyoson();

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の市区町村を選択してください。';
			// JavaScript
			$this->addMetaJs($this->_aplbaseurl . 'js/search/Selsikucyoson.js');

			$this->_data['selcity'] = array();
			$this->_data['selcity'] = $this->_model_sikucyoson->getShikucyosonData($this->_params);

	        // 表示用データに変換
        	$this->_model_sikucyoson->convertShikucyosonData($this->_data);

			$this->_main_helper = $this->_shikucyoson_helper;
		}

        // 沿線検索画面の出力（都道府県検索画面で検索時）
		else if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_ENSENEKI
		         && ! $this->_model_common->checkvalue($this->_params, "RailCd") )
		{
			$params = array(
					  'SrhKbn'  => $this->_params['SrhKbn']
					, 'SrhType' => $this->_params['SrhType']
					, 'PrefCd'  => $this->_params['PrefCd']
				);
			Apm_Util::redirect($this->_baseurl."search/chinryomadorisearch/ensen/", $params);
			exit();

            // 沿線モデル
		    $this->_model_ensen = new Search_Model_Selensen();

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の沿線を選択してください。';
			// JavaScript
			$this->addMetaJs($this->_aplbaseurl . 'js/search/Selensen.js');

			$this->_data['selensen'] = array();
			$this->_data['selensen'] = $this->_model_ensen->getEnsenDataExceptBusSonota($this->_params);

			$this->_data['PrefCd'] = array();
			$this->_data['PrefCd'] = $this->_params['PrefCd'];

			// 表示用データに変換
			$this->_model_ensen->convertEnsenData($this->_data);

			$this->_main_helper = $this->_ensen_helper;
		}
        // 駅検索画面の出力（都道府県検索画面で検索時）
		else if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_ENSENEKI
		         && ! $this->_model_common->checkvalue($this->_params, "StCd") )
		{
			$params = array(
					  'SrhKbn'  => $this->_params['SrhKbn']
					, 'SrhType' => $this->_params['SrhType']
					, 'PrefCd'  => $this->_params['PrefCd']
					, 'RailCd'  => $this->_params['RailCd']
				);
			Apm_Util::redirect($this->_baseurl."search/chinryomadorisearch/eki/", $params);
			exit();

            // 駅モデル
		    $this->_model_eki = new Search_Model_Seleki();

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の駅を選択してください。';
			// JavaScript
			$this->addMetaJs($this->_aplbaseurl . 'js/search/Seleki.js');

			$this->_data['seleki'] = array();
			$this->_data['seleki'] = $this->_model_eki->getEkiData($this->_params);

			$this->_data['PrefCd'] = array();
			$this->_data['PrefCd'] = $this->_params['PrefCd'];

			// 表示用データに変換
			$this->_model_eki->convertEkiData($this->_data);

			$this->_main_helper = $this->_eki_helper;
		}

		//賃料×間取り検索へ
		else if (  ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_JYUSYO
		         &&  $this->_model_common->checkvalue($this->_params, "CityCd") )
				|| ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_ENSENEKI
				 &&  $this->_model_common->checkvalue($this->_params, "RailCd") ) )
		{
			$params = array(
					  'SrhKbn'  => $this->_params['SrhKbn']
					, 'SrhType' => $this->_params['SrhType']
					, 'PrefCd'  => $this->_params['PrefCd']
					, 'RailCd'  => $this->_params['RailCd']
					, 'CityCd'  => $this->_params['CityCd']
					, 'StCd'    => $this->_params['StCd']
				);
			Apm_Util::redirect($this->_baseurl."search/chinryomadorisearch/matrix/", $params);
			exit();

			// JavaScript
			$this->addMetaJs($this->_aplbaseurl . 'js/search/Chinryomadori.js');

		    $this->_model_chinryomadori_matrix = new Search_Model_ChinryomadoriMatrix();
			// 表示用ラベル取得
			$this->_data['label'] = array();
			$this->_data['label'] = $this->_model_chinryomadori_matrix->getLabel($this->_params);
			// マトリクスデータ取得
			$result = $this->_model_chinryomadori_matrix->getMatrix($this->_params);
			// 表示用データに変換
			$this->_model_chinryomadori_matrix->convertMatrixData($result, $this->_params, $this->_data);

			$this->_main_helper = $this->_chinryomadori_helper;
		}
		////賃料×間取り検索の出力
		else
		{
        	//$this->_data['main_block']  = $this->_main_helper->getBlock($this->_data);
		}

        // 表示
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/search.tpl';

	}

	public function cityAction()
	{
		if (empty($this->_params['PrefCd']) || empty($this->_params["SrhType"])) {
			Apm_Util::redirect($this->_baseurl."chinryomadorisearch/");
			exit();
		}
		
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_CHINRYOMADORI, "chinryomadorisearch/city/");
		$this->_data['form_act'] = "chinryomadorisearch/matrix/";
		
		$this->setMainTemplate('cms_search.tpl');
		// テンプレート
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/chinryo.tpl';
		$this->_main_helper = $this->getApmHelper('selcity_renew.tpl');
		//$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/search.tpl';
		//$this->_main_helper = $this->_shikucyoson_helper;
		
		// H1のタイトル
		$this->_data['h1_title'] = 'ご希望の市区町村を選択してください。';
		// リード文
		$this->_data['read_text'] = "市町村区を選択し「間取りと家賃毎の物件を見る」をクリックすると、間取りと家賃毎の物件数を一覧表で確認できます。";
		//CSSの定義（デザイン）
		$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/search_share/chinryo/css/add.css',array('type' => 'text/css','media' => 'all'));
		// JavaScript
		$this->addMetaJs('/app/js/search/Selsikucyoson.js');
		// 単一選択用フラグ
		$this->_data['SelFlag'] = 1;
		// 市区町村選択なし
		$this->_data['SelCyoNull'] = "1";
		// 物件検索なし
		$this->_data['RstNull'] = "1";
		
		// 検索ボタン
		$this->_data['search_button_tpl'] = APPLICATION_PATH . '/modules/search/views/helpers/btn_chinryo_city.tpl';
		
		// 市区町村モデル
		$this->_model_sikucyoson = new Search_Model_Selsikucyoson();
		$this->_data['selcity'] = array();
		$this->_data['selcity'] = $this->_model_sikucyoson->getShikucyosonData($this->_params);
		// 表示用データに変換
		$this->_model_sikucyoson->convertShikucyosonData($this->_data);
	}

	public function ensenAction()
	{
		if (empty($this->_params['PrefCd']) || empty($this->_params["SrhType"])) {
			Apm_Util::redirect($this->_baseurl."chinryomadorisearch/");
			exit();
		}
		
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_CHINRYOMADORI, "chinryomadorisearch/ensen/");
		$this->_data['form_act'] = "chinryomadorisearch/eki/";
		
		$this->setMainTemplate('cms_search.tpl');
		// テンプレート
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/chinryo.tpl';
		$this->_main_helper = $this->getApmHelper('selensen_renew.tpl');
		//$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/search.tpl';
		//$this->_main_helper = $this->_ensen_helper;
		
		// H1のタイトル
		$this->_data['h1_title'] = 'ご希望の沿線を選択してください。';
		// リード文
		$this->_data['read_text'] = "沿線を選択し「駅を選択」をクリックすると、駅選択の画面が開きます。";
		//CSSの定義（デザイン）
		$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/search_share/chinryo/css/add.css',array('type' => 'text/css','media' => 'all'));
		// JavaScript
		$this->addMetaJs('/app/js/search/Selensen.js');
		// 単一選択用フラグ
		$this->_data['SelFlag'] = 1;
		// 物件検索なし
		$this->_data['RstNull'] = "1";
		
		// 検索ボタン
		$this->_data['search_button_tpl'] = APPLICATION_PATH . '/modules/search/views/helpers/btn_chinryo_rail.tpl';
		
		// 沿線モデル
		$this->_model_ensen = new Search_Model_Selensen();
		$this->_data['selensen'] = array();
		$this->_data['selensen'] = $this->_model_ensen->getEnsenDataExceptBusSonota($this->_params);
		$this->_data['PrefCd'] = array();
		$this->_data['PrefCd'] = $this->_params['PrefCd'];
		
		// 表示用データに変換
		$this->_model_ensen->convertEnsenData($this->_data);
	}

	public function ekiAction()
	{
		if (empty($this->_params['RailCd']) || empty($this->_params["SrhType"])) {
			Apm_Util::redirect($this->_baseurl."chinryomadorisearch/");
			exit();
		}
		
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_CHINRYOMADORI, "chinryomadorisearch/eki/");
		$this->_data['form_act'] = "chinryomadorisearch/matrix/";
		
		$this->setMainTemplate('cms_search.tpl');
		// テンプレート
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/chinryo.tpl';
		$this->_main_helper = $this->getApmHelper('seleki_renew.tpl');
		//$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/search.tpl';
		//$this->_main_helper = $this->_eki_helper;
		
		// H1のタイトル
		$this->_data['h1_title'] = 'ご希望の駅を選択してください。';
		// リード文
		$this->_data['read_text'] = "駅を選択し「間取りと家賃毎の物件を見る」をクリックすると、間取りと家賃毎の物件数を一覧表で確認できます。";
		//CSSの定義（デザイン）
		$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/search_share/chinryo/css/add.css',array('type' => 'text/css','media' => 'all'));
		// JavaScript
		$this->addMetaJs('/app/js/search/Seleki.js');
		// 単一選択用フラグ
		$this->_data['SelFlag'] = 1;
		// 物件検索なし
		$this->_data['RstNull'] = "1";
		
		// 検索ボタン
		$this->_data['search_button_tpl'] = APPLICATION_PATH . '/modules/search/views/helpers/btn_chinryo_eki.tpl';
		
		// 駅モデル
		$this->_model_eki = new Search_Model_Seleki();
		$this->_data['seleki'] = array();
		$this->_data['seleki'] = $this->_model_eki->getEkiData($this->_params);
		$this->_data['PrefCd'] = array();
		$this->_data['PrefCd'] = $this->_params['PrefCd'];
		
		// 表示用データに変換
		$this->_model_eki->convertEkiData($this->_data);
	}

	public function matrixAction()
	{
		if (empty($this->_params["SrhType"])) {
			Apm_Util::redirect($this->_baseurl."chinryomadorisearch/");
			exit();
		}
		
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_CHINRYOMADORI, "chinryomadorisearch/matrix/");
		//$this->_data['form_act'] = "chinryomadorisearch/matrix/";
		
		$this->setMainTemplate('cms_search.tpl');
		// テンプレート
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/chinryo.tpl';
		$this->_main_helper = $this->getApmHelper('chinryomadori_matrix.tpl');
		//$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/search.tpl';
		//$this->_main_helper = $this->_chinryomadori_helper;
		
		// H1のタイトル
		$this->_data['h1_title'] = '賃料×間取りから検索';
		$this->_data['SrhType'] = $this->_params['SrhType'];
		$this->_data['PrefCd']  = $this->_params['PrefCd'][0];
		// リード文
		if ($this->_params["SrhType"] == Apm_Config_Search::SRHTYPE_JYUSYO) {
			$this->_data['read_text'] = "市区町村ごとの物件数を間取り別にご覧いただけます。数値をクリックしていただくと、物件の一覧がご覧いただけます。";
		} else {
			$this->_data['read_text'] = "駅ごとの物件数を間取り別にご覧いただけます。数値をクリックしていただくと、物件の一覧がご覧いただけます。";
			$this->_data['RailCd'] = $this->_params['RailCd'][0];
		}
		//CSSの定義（デザイン）
		$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/search_share/chinryo/css/add.css',array('type' => 'text/css','media' => 'all'));
		$this->addMetaCss('/search_share/css/index.css',array('type' => 'text/css','media' => 'all'));
		// JavaScript
		$this->addMetaJs('/app/js/search/Chinryomadori.js');
		
		// マトリクスモデル
		$this->_model_chinryomadori_matrix = new Search_Model_ChinryomadoriMatrix();
		// 表示用ラベル取得
		$this->_data['label'] = array();
		$this->_data['label'] = $this->_model_chinryomadori_matrix->getLabel($this->_params);
		// マトリクスデータ取得
		$result = $this->_model_chinryomadori_matrix->getMatrix($this->_params);
		// 表示用データに変換
		$this->_model_chinryomadori_matrix->convertMatrixData($result, $this->_params, $this->_data);
	}

}
?>